from fastapi import FastAPI

# 创建 FastAPI 实例
app = FastAPI()


# 定义根路由
@app.get("/")
def read_root():
    return {"message": "欢迎来到 FastAPI 世界！"}


# 启动命令：uvicorn main:app --reload
import uvicorn

if __name__ == '__main__':
    # main是文件名称, : app 是实例变量名
    uvicorn.run(app='main:app', host="127.0.0.1", port=8080, reload=True)

# 运行前安装:
# pip install fastapi uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple